/*
 * Package il.ac.biu.cs.grossmm.impl.simple
 * File RequestProcessException.java
 * 
 * This is a part of presence service framework prototype. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package il.ac.biu.cs.grossmm.api.simple;

import java.util.ArrayList;
import java.util.List;

import javax.sip.header.Header;

/**
 * An exception convertabale to SIP response. Should be used with cation (given
 * the slow exception processing mechanisms of java).
 * 
 */
public class RequestProcessException extends Exception {
	private static final long serialVersionUID = -2227562878124341861L;

	private int code;

	private String reason;

	private List<Header> headers = null;

	/**
	 * Creates a new <tt>RequestProcessException</tt> by response code and a
	 * reason
	 * 
	 * @param code
	 *            the response code
	 * @param reason
	 *            the human readable reason
	 */
	public RequestProcessException(int code, String reason) {
		super(code + " " + reason);

		this.code = code;
		this.reason = reason;
	}

	/**
	 * Sets a header for response
	 * @param header the header to set
	 */
	public void setHeader(Header header) {
		if (headers == null)
			headers = new ArrayList<Header>();
		headers.add(header);
	}

	/**
	 * Gets the response code
	 * @return the response code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * Gets the human readable reason
	 * @return the human readable reason
	 */
	public String getReason() {
		return reason;
	}

	/**
	 * Gets the list of SIP headers
	 * @return the list of SIP headers
	 */
	public List<Header> getHeaders() {
		return headers;
	}
}
